import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class StockSpanner {

    public static void main(String[] args) {
        StockSpanner stockSpanner = new StockSpanner();
        System.out.println(stockSpanner.next(28));
        System.out.println(stockSpanner.next(24));
        System.out.println(stockSpanner.next(28));
        System.out.println(stockSpanner.next(35));
    }

    private List<Integer> list;
    private Stack<Integer> stack = null;
    private int i;
    public StockSpanner() {
        stack = new Stack<>();
        i = 0;
        list = new ArrayList<>();
    }

    public int next(int price) {
        while (!stack.isEmpty() && price >= list.get(stack.peek())) {
            stack.pop();
        }
        list.add(price);
        int k = -1;
        if (!stack.isEmpty()) k = stack.peek();
        stack.push(i);
        int ans = i - k;
        i++;
        return ans;
    }
}